import http from "./http";
// 请求登录的api
export const loginApi = (
  params: ILoginForm
): Promise<MyResponse<{ tokenHead: string; token: string }>> =>
  http.post("/admin/login", params);

// 请求当前用户信息的api
export const getUserInfoApi = (): Promise<MyResponse<UserInfoResponse>> =>
  http.get("/admin/info");

export const getAdminListApi = (
  params: AdminListParams,
  signal: AbortSignal
): Promise<MyResponse<TabelListResponse<Admin>>> =>
  http.get("/admin/list", { params, signal });

// 添加用户的请求
export const registerUserApi = (
  params: FormAdmin
): Promise<MyResponse<Admin>> => http.post("/admin/register", params);

// 要求id获取一个指定用户的信息
export const getAdminInfoByIdApi = (id: number): Promise<MyResponse<Admin>> =>
  http.get(`/admin/${id}`);

// 修改用户信息
export const updateUserInfoApi = (
  params: FormAdmin
): Promise<MyResponse<any>> => http.post(`admin/update/${params.id}`, params);

// 根据用户id获取已有的角色
export const getUserRoleApi = (id: number): RSP<Role[]> =>
  http.get(`admin/role/${id}`);

// 获取所有角色
export const getAllRoleListApi = (): RSP<Role[]> => http.get("/role/listAll");

export const allocRoleForAdminApi = (params: AllocRoleParams): RSP<any> =>
  http.post(
    `/admin/role/update?adminId=${params.adminId}&roleIds=${params.roleIds.join(
      ","
    )}`
  );
// 上面的传参，其实也可以使用qs模块，帮我们把参数进行转换
// http.post(`url?${qs.stringify(params)}`)
// post请求的api，还可以是 http.post(url,body参数,配置对象); 配置对象里面还可以传 query参数
// http.post(url,null,{ params : params })
